Page 137 - 2629_Devagiri_C-8
P. 137

21 st   #Technology Literacy
                                                                                          Century
                                                                                           Skills  #Critical Thinking
                  5.   Write a Python program to demonstrate the use of the break
                     statement within a for loop, By following the given instructions:

                          Create a for loop that iterates through numbers from 0 to 11 using the range() function.
                          Inside the loop, add an if statement to check when the number is equal to 7.
                          When the number reaches 7, use the break statement to exit the loop immediately.

                          After breaking out of the loop, print the number at the point where the loop was exited.

                           Also,  print  a message saying  "Out  of loop"  to indicate  that  the  loop  has finished
                           execution.


                     Program.py
                  File  Edit  Format   Run    Options   Window    Help

                  Python 3.13.7 (tags/v3.13.7:bceelc3, Aug 14 2025, 14:15:11) [MSC v.1944 64
                  bit ( AMD64)] on win32
                  Enter "help" below or click "Help" above for more information.
                  =      RESTART:       C:/Users/Ankita          Kapoor/AppData/Local/Programs/Python/
                  Python313/1.py =
                  Number is: 0
                  Number is: 1
                  Number is: 2
                  Number is: 3
                  Number is: 4
                  Number is: 5
                  Number is: 6
                  Out of loop




                     Output
                  Number is: 0
                  Number is: 1
                  Number is: 2
                  Number is: 3
                  Number is: 4
                  Number is: 5
                  Number is: 6
                  Out of loop














                                                                                                                  135
                                                                                                   Project Practice
   132   133   134   135   136   137   138   139   140   141   142